package com.zhang.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.w3c.dom.Text;

import com.zhang.little_sample.R;

/**
 * Created by admin on 2015/10/19.
 */
public class Main extends Activity{
    private static TextView shwodialog_textview;
    private static TextView show_exit_textview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        shwodialog_textview=(TextView)findViewById(R.id.main_show_dialog);
        shwodialog_textview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Dialog dialog=createLoadingDialog(Main.this,"Wait...");
                dialog.show();
            }
        });
        show_exit_textview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    public static Dialog createLoadingDialog(Context context,String msg){
        LayoutInflater inflater=LayoutInflater.from(context);
        View v=inflater.inflate(R.layout.loading_dialog, null);
        LinearLayout layout=(LinearLayout) v.findViewById(R.id.dialog_view);
        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
        TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);
        AnimationDrawable animationDrawable=(AnimationDrawable)spaceshipImage.getBackground();

        tipTextView.setText(msg);
        Dialog loadingDialog=new Dialog(context,R.style.loading_dialog);
        loadingDialog.setCancelable(true);// 不可以用“返回键”取消
        loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));
        animationDrawable.start();
        return loadingDialog;
    }
}
